package com.rpp;

import com.rpp.config.DruidConfig;
import com.rpp.config.ZkConfig;
import com.rpp.utils.DatasourceUtil;
import com.rpp.utils.ZookeeperUtil;
import org.I0Itec.zkclient.ZkClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

/**
 * @Description
 * @Author rpp
 * @Date 2020/8/11 12:21 上午
 */
@SpringBootApplication
public class TestApplication {

    @Autowired
    ZkConfig zkConfig;
    @Autowired
    DruidConfig druidConfig;

    public static void main(String[] args) {
        SpringApplication.run(TestApplication.class, args);
    }

    /**
     * zookeeper客户端连接放入spring容器管理，全局共享
     *
     * @return
     */
    @Bean
    public ZkClient zkClient() {
        ZkClient zkClient = ZookeeperUtil.createSession(zkConfig.getIp(), zkConfig.getPort());

        //初始化数据库连接池
        DatasourceUtil.initDatasource(druidConfig, zkClient);

        return zkClient;
    }

}
